package servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import entity.User;
import entity.UserInfo;

import serviceImpl.login;
import serviceImpl.queryMod;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "LoginServlet", value = "/LoginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");

        String account = request.getParameter("account");
        String password = request.getParameter("password");
     //   System.out.println(account + password);
        PrintWriter out = response.getWriter();

        login l=new login();
        User login = l.login(account, password);



        if(login!=null){
            String text="您的用户名为：\n"+account+"您的密码为: \n"+password;
            request.getSession().setAttribute("user",login);
            out.print(text);

        }else{
            String text="用户名或密码错误！";
            out.print(text);

    }


    }
}
